package cn.dnuihyy406.dnuifood_16110100406.controller.mefragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.List;

import cn.dnuihyy406.dnuifood_16110100406.R;
import cn.dnuihyy406.dnuifood_16110100406.bean.GetCommentBean;
import cn.dnuihyy406.dnuifood_16110100406.listener.OnRetrofitListener;
import cn.dnuihyy406.dnuifood_16110100406.model.UserImformationModel;

public class MyOrderActivity extends AppCompatActivity implements OnRetrofitListener<Object>{
    private RecyclerView recyclerView;
    private MyOrderAdapter myOrderAdapter;
    SharedPreferences sharedPreferences;
    String user_id;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_order);
        sharedPreferences = getSharedPreferences("hyy", Context.MODE_PRIVATE);
        user_id = sharedPreferences.getString("userid","");
        initViews();
        initData();
    }

    @Override
    public void onSuccess(Object object, int flag) {
        myOrderAdapter=new MyOrderAdapter(MyOrderActivity.this, (List) object);
        recyclerView.setAdapter(myOrderAdapter);
    }

    @Override
    public void onFailure(String msg) {
        Toast.makeText(MyOrderActivity.this,msg,Toast.LENGTH_SHORT).show();
    }

    void initViews(){
        recyclerView=this.findViewById(R.id.rv1);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }
    void initData(){
        getmyorder();
    }

    private void getmyorder(){
        UserImformationModel userImformationModel=new UserImformationModel();
        userImformationModel.getAllOrdersByUser(user_id,this);
    }
}